<!--
 * @Author: your name
 * @Date: 2022-04-02 23:18:31
 * @LastEditTime: 2022-04-03 00:17:24
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\双周赛.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
 * @param {string} s
 * @return {number}
 */
        /**
 * @param {string} s
 * @return {number}
 */
        /**
 * @param {string} s
 * @return {number}
 */
        var numberOfWays = function (s) {
            let arrZero = [], arrOne = [];
            let leftZero = 0, leftOne = 0;
            let Zeronum = 0, Onenum = 0;
            for (let i = s.length - 1; i >= 0; i--) {
                if (s[i] === '0') {
                    leftZero++;
                    arrZero[i] = Zeronum + leftOne;
                    Zeronum = arrZero[i];
                }
                if (s[i] === '1') {
                    leftOne++;
                    arrOne[i] = Onenum + leftZero;
                    Onenum = arrOne[i];
                }
            }
            let result = 0;
            leftZero = 0, leftOne = 0;
            for (let i = 0; i < s.length; i++) {
                if (s[i] === '0') {
                    leftZero++;
                    result += leftOne * arrZero[i];
                }
                if (s[i] === '1') {
                    leftOne++;
                    result += leftZero * arrOne[i];
                }
            }
            return result;
        };
        console.log(numberOfWays("001101"));
    </script>
</body>

</html>